package com.ruoyi.project.pms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.pms.domain.PmsBrand;
import com.ruoyi.db.pms.domain.query.PmsBrandQueryVo;
import com.ruoyi.project.pms.service.PmsBrandService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 品牌管理Controller
 *
 * @author ruoyi
 * @date 2020-04-22
 */
@Api(tags="pms管理：品牌管理管理")
@RestController
@RequestMapping("/pms/brand")
public class PmsBrandController extends BaseController
{
    @Autowired
    private PmsBrandService pmsBrandService;

    @ApiOperation("查询品牌管理列表")
    @PreAuthorize("@ss.hasPermi('pms:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsBrandQueryVo pmsBrandQueryVo)
    {
        startPage();
        List<PmsBrand> list = pmsBrandService.selectPmsBrandList(pmsBrandQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出品牌管理列表")
    @Log(title = "品牌管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('pms:brand:export')")
    @GetMapping("/export")
    public AjaxResult export(PmsBrandQueryVo pmsBrandQueryVo)
    {
        List<PmsBrand> list = pmsBrandService.selectPmsBrandList(pmsBrandQueryVo);
        ExcelUtil<PmsBrand> util = new ExcelUtil<PmsBrand>(PmsBrand.class);
        return util.exportExcel(list, "brand");
    }

    @ApiOperation("获取品牌管理详细信息")
    @Log(title = "品牌管理", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:brand:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsBrandService.selectPmsBrandById(id));
    }

    @ApiOperation("新增品牌管理")
    @Log(title = "品牌管理", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('pms:brand:add')")
    @PostMapping
    public AjaxResult add(@RequestBody PmsBrand pmsBrand)
    {
        return toAjax(pmsBrandService.insertPmsBrand(pmsBrand));
    }

    @ApiOperation("修改品牌管理")
    @Log(title = "品牌管理", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('pms:brand:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody PmsBrand pmsBrand)
    {
        return toAjax(pmsBrandService.updatePmsBrand(pmsBrand));
    }

    @ApiOperation("删除品牌管理")
    @Log(title = "品牌管理", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('pms:brand:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsBrandService.deletePmsBrandByIds(ids));
    }
}
